<?php

App::uses('AppModel', 'Model');

/**
 * Customer Model
 *
 * @property Address $Address
 * @property CustomerData $CustomerData
 */
class Customer extends AppModel {

    /**
     * Validation rules
     *
     * @var array
     */
    public $validate = array(
        'first_name' => array(
            'notEmpty' => array(
                'rule' => array('notEmpty'),
                'message' => 'Please enter first name.',
            //'allowEmpty' => false,
            //'required' => false,
            //'last' => false, // Stop validation after this rule
            //'on' => 'create', // Limit validation to 'create' or 'update' operations
            ),
        ),
        'last_name' => array(
            'notEmpty' => array(
                'rule' => array('notEmpty'),
                'message' => 'Please enter last name.',
            //'allowEmpty' => false,
            //'required' => false,
            //'last' => false, // Stop validation after this rule
            //'on' => 'create', // Limit validation to 'create' or 'update' operations
            ),
        ),
        'mobile' => array(
            'notEmpty' => array(
                'rule' => array('notEmpty'),
                'message' => 'Please enter mobile.',
            //'allowEmpty' => false,
            //'required' => false,
            //'last' => false, // Stop validation after this rule
            //'on' => 'create', // Limit validation to 'create' or 'update' operations
            ),
        ),
        'email' => array(
            'email' => array(
                'rule' => array('email'),
                'message' => 'Please enter email.',
            //'allowEmpty' => false,
            //'required' => false,
            //'last' => false, // Stop validation after this rule
            //'on' => 'create', // Limit validation to 'create' or 'update' operations
            ),
        ),
    );

    //The Associations below have been created with all possible keys, those that are not needed can be removed

    /**
     * hasMany associations
     *
     * @var array
     */
    public $hasMany = array(
        'Address' => array(
            'className' => 'Address',
            'foreignKey' => 'customer_id',
            'dependent' => false,
            'conditions' => '',
            'fields' => '',
            'order' => '',
            'limit' => '',
            'offset' => '',
            'exclusive' => '',
            'finderQuery' => '',
            'counterQuery' => ''
        ),
        'CustomerData' => array(
            'className' => 'CustomerData',
            'foreignKey' => 'customer_id',
            'dependent' => false,
            'conditions' => '',
            'fields' => '',
            'order' => '',
            'limit' => '',
            'offset' => '',
            'exclusive' => '',
            'finderQuery' => '',
            'counterQuery' => ''
        )
    );
    
    public function listAll(){
        $data = $this->find('all',array(
            'order'=>array('Customer.created desc')
        ));
        
        return $data;
    }
    
    public function getAllDetails($id){
        $data = $this->Find('first',array(
            'conditions'=>array('Customer.id'=>$id),
//            'joins'=>array(
//                array(
//                    'table' => 'property_types',
//                    'alias' => 'PropertyType',
//                    'conditions' => array(
//                        'CustomerData.property_type_id = PropertyType.id'
//                    )
//                ),
//            )
        ));
        
        return $data;
    }

}
